package com.fl.scheduler;

import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.TriggerBuilder.newTrigger;

import org.apache.log4j.Logger;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;

import com.fl.sys.SysConfig;
import com.fl.util.SchedulerUtil;

public class FtpTask {

	private static final Logger log = Logger.getLogger(FtpTask.class);

	public void start(String timeRegx) throws Exception {

		if (SysConfig.getSysScheduler().checkExists(SchedulerUtil.getJobKey())) {
			throw new Exception("请先停止旧任务后再启动新任务！");
		}

		JobDetail job = JobBuilder.newJob(FtpJob.class)
				.withIdentity(SchedulerUtil.getJobKey()).build();

		CronTrigger trigger = newTrigger()
				.withIdentity(SchedulerUtil.getTriggerKey())
				.withSchedule(cronSchedule(timeRegx)).build();

		SysConfig.getSysScheduler().scheduleJob(job, trigger);
	}
}
